package com.cts.learninglibrary.controller;

import com.cts.learninglibrary.service.LoginService;
import com.cts.learninglibrary.util.R;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author arctique
 * @date 2020/8/24 11:46
 */
@RestController
@RequestMapping
@CrossOrigin
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     *
     * @param username
     * @param password
     * @return R
     */
    @PostMapping("/login")
    public R login(@RequestParam @NonNull String username,
                   @RequestParam @NonNull String password) {
        return loginService.login(username, password);
    }

    /**
     * 登出
     *
     * @return R
     */
    @PostMapping("/logout")
    public R logout() {
        return loginService.logout();
    }

    /**
     * 无权访问
     *
     * @return R
     */
    @GetMapping(value = "/noAccess")
    public R noAccess() {
        return R.failed("无权访问!");
    }

    /**
     * 登录踢出
     * @return R
     */
    @GetMapping(value = "/kickOut")
    public R kickOut() {
        return R.failed("您的账号已在其他地方登陆，您已被登出");
    }

    /**
     * 没有登录
     *
     * @return R
     */
    @GetMapping(value = "/notLogin")
    public R notLogin() {
        return R.failed("您没有登陆，请重新登陆");
    }

}
